package com.tql.mall.web.controller;

import com.tql.mall.common.constant.PageConstant;
import com.tql.mall.model.product.SkuInfo;
import com.tql.mall.product.client.ProductFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @Author: tyk
 * @Date: 2023/5/25 20:44
 * @Description:
 */
@Controller
public class CartWebController {

    @Autowired
    private ProductFeignClient productFeignClient;

    /**
     * 跳转到购物车页面
     */
    @GetMapping("cart.html")
    public String index() {
        return "cart/index";
    }

    /**
     * 跳转到商品成功添加到购物车的页面
     */
    @GetMapping("addCart.html")
    public String addCart(Long skuId, Integer skuNum, Model model) {

        // 商品ID、名称、图片、数量
        SkuInfo skuInfo = productFeignClient.getSkuInfo(skuId);

        // 传递数据到页面
        model.addAttribute(PageConstant.SKU_INFO, skuInfo);
        model.addAttribute(PageConstant.SKU_NUM, skuNum);

        return "cart/addCart";
    }

}
